package com.example.onlinemusicplayer.service;

import com.example.onlinemusicplayer.mapper.LoveMusicMapper;
import com.example.onlinemusicplayer.model.Music;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LoveMusicService {
    @Autowired
    private LoveMusicMapper loveMusicMapper;

    // 查询此次收藏音乐是否之前收藏过
    public Music findLoveMusicByMusicIdAndUserId(Integer userid,Integer musicid){
        return loveMusicMapper.findLoveMusicByMusicIdAndUserId(userid,musicid);
    }
    // 向 数据表 lovemusic 插入一条信息
    public boolean insertLoveMusic(Integer userid,Integer musicid){
        return loveMusicMapper.insertLoveMusic(userid,musicid);
    }

    //     如果没有传入 歌曲名/字符，显示当前用户收藏的所有音乐
    public List<Music> findLoveMusicByUserId(Integer user_id){
        return loveMusicMapper.findLoveMusicByUserId(user_id);
    }

    //    反之，传入了 歌曲名/字符，进行模糊查询。
    public List<Music> findLoveMusicByKeyAndUserId(String title,Integer user_id){
        return loveMusicMapper.findLoveMusicByKeyAndUserId(title,user_id);
    }

    // 根据 userId 和 musicId 来删除（移除）收藏表中的信息
    public Integer deleteLoveMusic(Integer userid,Integer musicid){
        return loveMusicMapper.deleteLoveMusic(userid,musicid);
    }

    // 根据 musicid 删除收藏表上的信息
    public Integer deleteLoveMusicById(Integer musicid){
        return loveMusicMapper.deleteLoveMusicById(musicid);
    }

}
